package com.example.music;

import android.app.Activity;
import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.annotation.Nullable;

public class TitleLayout extends LinearLayout {
    //定义UI组件对象
    ImageView img_back;
    TextView txt_title;
    public TitleLayout(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
        LayoutInflater.from(context).inflate(R.layout.title_layout,this);
        //初始化组件对象
        initViews();
    }

    private void initViews() {
        img_back=this.findViewById(R.id.img_back);
        txt_title=this.findViewById(R.id.txt_title);
        //设置返回按钮图片的单击事件
        img_back.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View view) {
                //返回上一个Activity
                ((Activity)getContext()).finish();
                //停止播放音乐
                MusicData.stopMedia();
            }
        });
    }
    //修改公共标题栏的标题内容
    public void  setTitle(String title){
        txt_title.setText(title);
    }
}
